import 'package:beamer/beamer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

GlobalKey<_GoodsDetailsTitleState> goodsDetailsTitleKey = GlobalKey(debugLabel: 'goodsDetailsTitle');

class GoodsDetailsTitle extends StatefulWidget {

  final AsyncValue goodsDetailsData;
  const GoodsDetailsTitle({Key? key, required this.goodsDetailsData}) : super(key: key);

  @override
  State<GoodsDetailsTitle> createState() => _GoodsDetailsTitleState();
}

class _GoodsDetailsTitleState extends State<GoodsDetailsTitle> {
  double opacityState = 1.0;

  void getGoodsDetailsPageOpacity(double opacity) {
    setState(() {
      opacityState = 1.0 - opacity;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Positioned(
      top: 0,
      left: 0,
      child: Opacity(
        opacity: opacityState.abs() > 1.0 ? 1.0 : opacityState.abs(),
        child: Column(
          children: [
            SizedBox(
              height: MediaQuery.of(context).padding.top,
            ),
            Container(
              width: MediaQuery.of(context).size.width,
              height: 40,
              alignment: Alignment.centerLeft,
              child: widget.goodsDetailsData.when(data: (data) {
                return Container(
                      width: 40,
                      height: 40,
                      clipBehavior: Clip.antiAlias,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(25),
                        color: const Color.fromARGB(96, 0, 206, 137),
                      ),
                      child: GestureDetector(
                        onTap: () => {
                          Beamer.of(context).beamBack(),
                        },
                        child: const Icon(
                          Icons.chevron_left_outlined,
                          size: 28,
                          color: Colors.white,
                        ),
                      ),
                    );
              }, error: (error, StackTrace) {
                return const Text("數據錯誤");
              }, loading: () {
                return null;
              }),
            ),
          ],
        ),
      ),
    );
  }
}
